package Swing;

import javax.swing.*;
import java.awt.*;

public class Tet_Icon extends JFrame implements Icon {
    private int width;
    private int height;
    public Tet_Icon(int width, int height) {
        this.width = width;
        this.height = height;
    }

    public Tet_Icon()  {}//无参构造
    public void init(){
        Tet_Icon icon = new Tet_Icon(20,20);
        //图标可以放在标签上，也可以放到按钮上
        JLabel label = new JLabel("Icon_Test",icon,SwingConstants.CENTER);
        Container container = new Container();
        container.add(label);
        this.setVisible(true);
        setBounds(100,100,300,300);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fillOval(x,y,width,height);//画一个圆
    }

    @Override
    public int getIconWidth() {
        return this.width;
    }

    @Override
    public int getIconHeight() {
        return this.height;
    }

    public static void main(String[] args) {
        new Tet_Icon().init();
    }
}
